package com.example.service.impl;

import com.app.commons.beans.UserInfo;
import com.app.commons.utils.Dto;
import com.app.commons.utils.Page;
import com.app.dao.UserMapper;
import com.app.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Dto<Page<UserInfo>> getPageUsers(Integer pageIndex, Integer pageSize) {
        //查询分页的用户集合
        Integer fromIndex = (pageIndex - 1) * pageSize;
        List<UserInfo> userList = userMapper.getPageUserList(fromIndex, pageSize);

        //查询用户个数
        Integer totalCount = userMapper.getUserCount();

        //封装结果为分页对象
        Page<UserInfo> pageUsers = new Page<>(pageIndex,pageSize,totalCount,userList);

        //封装数据传输对象
        Dto<Page<UserInfo>> dto = new Dto<>(pageUsers,"0000","查询成功");

        return dto;
    }
}
